package com.gec.hawaste.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gec.hawaste.entity.SysRole;
import com.gec.hawaste.service.ISysRoleService;
import com.gec.hawaste.utils.PageInfo;
import com.gec.hawaste.utils.ResultBean;
import com.gec.hawaste.vo.SysRoleDo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author chenxys
 * @since 2022-07-01
 */
@Slf4j
@RestController
@RequestMapping("/manager/role")
public class SysRoleController {
    @Autowired
    private ISysRoleService roleService;

    @GetMapping("/select/{current}/{size}")
    public ResultBean<Page> select(@PathVariable("current") Long current,
                                   @PathVariable("size") Long size,
                                   @RequestParam Map<String,Object> params){

        PageInfo<SysRoleDo> pageInfo = (PageInfo<SysRoleDo>) roleService.selectByCondition(new PageInfo<>(current,size),params);
        log.info("角色列表分页查询");
        pageInfo.setNavigatePage();
        return ResultBean.ok(pageInfo);
    }

    @GetMapping("/delete")
    public ResultBean delete(Long id){
        roleService.removeById(id);
        log.info("删除角色");
        return ResultBean.ok();
    }

    @GetMapping("/selectOne")
    public ResultBean<SysRoleDo> selectOne(Long id){
        SysRoleDo role = roleService.getByRoleId(id);
        log.info("查询单个");
        return ResultBean.ok(role);
    }
}
